/**
 * Created by wanghuan on 2017/4/9.
 */

/*==========================schedule 相关接口==============================*/

import Ajax from '../../apiAjax';

export  default {
  state:{
    daySchedule:{},
    weekSchedule:{},
    monthSchedule:{}
  },
  mutations:{
    setCommonStateData(state,{key,data}){
      state[key] = data;
    }
  },
  actions:{
    getDaySchedule({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/schedule/getScheInWeek',
          data:paramData,
          success:function (data) {
            console.log(data)
            commit('setCommonStateData',{key:'daySchedule',data:data.data});
            resolve(data);
          }
        })
      })
    },
    getWeekSchedule({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/schedule/getScheInWeek',
          data:paramData,
          success:function (data) {
            console.log(data)
            commit('setCommonStateData',{key:'weekSchedule',data:data.data});
            resolve(data);
          }
        })
      })
    },
    getMonthSchedule({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/schedule/getScheOfMonth',
          data:paramData,
          success:function (data) {
            console.log(data)
            commit('setCommonStateData',{key:'monthSchedule',data:data.data});
            resolve(data);
          }
        })
      })
    },
    /**
     *
     * @param commit
     * @param paramData
     * {	"scheduleId":111,
        "scheRepeatId":1111,	// 点击排班，用来判断是否是操作单个排班，还是系	列排班
        "typeId":1	// 看上图，标识位，但是调的是统一接口，1是个人，2是系列
        }
     * @returns {Promise}
     */
    getScheduleDetail({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/schedule/getScheDetail',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    saveSchedule({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/schedule/saveSchedule',
          data:JSON.stringify(paramData),
          contentType: "application/json;charset=UTF-8",
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
  },
  getters: {
    daySchedule:(state, getters)=> {
      return state.daySchedule;
    },
    weekSchedule:(state, getters)=> {
      return state.weekSchedule;
    },
    monthSchedule:(state, getters)=> {
      return state.monthSchedule;
    }
  }
}
